package com.myres.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.myres.model.Series;

public class SeriesDao extends HibernateDaoSupport {
	public Series get(int id) {
		return getHibernateTemplate().get(Series.class, id);
	}

	public int save(Series series) {
		getHibernateTemplate().save(series);
		return series.getId();
	}

	public int update(Series series) {
		getHibernateTemplate().update(series);
		return series.getId();
	}

	public void delete(Series series) {
		getHibernateTemplate().delete(series);
	}

	public void delete(int id) {
		delete(get(id));
	}
	
	@SuppressWarnings("unchecked")
	public List<Series> findByName(String name){
		String hql = "from Series s where s.name like '%"+name+"%'";
		return (List<Series>)getHibernateTemplate().find(hql);
	}
	
	@SuppressWarnings("unchecked")
	public List<Series> findAll(){
		String hql = "from Series";
		return (List<Series>)getHibernateTemplate().find(hql);
	}
}
